'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = (app) => {
  const { router, controller, middleware } = app;
  const jwt = middleware.jwt(app.config.jwt);
  router.get('/token', controller.home.index);
  router.post('/login/account', controller.home.login);
  router.post('/login/outLogin', controller.home.outLogin);
  router.get('/currentUser', controller.home.currentUser);
  setUserRouter(router, controller, jwt);
  setAnimalRouter(router, controller, jwt);
  setUploadFileRouter(router, controller, jwt);
  setQiniuUploadFileRouter(router, controller, jwt);
  setBackGroundImageTypesRouter(router, controller, jwt);
  setBackGroundImagesRouter(router, controller, jwt);
};

function setUserRouter(router, controller, jwt) {
  // router.get('/user/:id', controller.user.show); // 获取单个人员数据
  // router.post('/user', controller.user.create); // 添加人员
  // router.put('/user/:id', controller.user.update); // 修改人员
  // router.delete('/user/:id', controller.user.destroy); // 删除人员
  router.resources('user', '/api/user', jwt, controller.user);
}

function setAnimalRouter(router, controller, jwt) {
  router.resources('animal', '/api/animal', jwt, controller.animal);
}

function setUploadFileRouter(router, controller, jwt) {
  router.post('/upload/uploadAvatar', jwt, controller.upload.uploadAvatar);
}

// 七牛云上传文件
function setQiniuUploadFileRouter(router, controller, jwt) {
  router.post('/upload', jwt, controller.utils.uploadFiles);
}

// 壁纸curd
function setBackGroundImagesRouter(router, controller, jwt) {
  router.resources(
    'backGroundImages',
    '/bizhi',
    jwt,
    controller.backGroundImages
  );
}

// 壁纸类型curd
function setBackGroundImageTypesRouter(router, controller, jwt) {
  router.resources(
    'backGroundImageTypes',
    '/bizhi/type',
    jwt,
    controller.backGroundImageTypes
  );
}
